<?php


class Login_Model extends Model {

	public function __construct(){
			parent::__construct();
			//echo  md5('karen');	
	}


	public function loginexec(){
	
		$statement = $this->db->prepare("SELECT id, role FROM users WHERE login=:login AND password=md5(:password)");
		$statement->execute( array(':login' => $_POST['login-username'],':password' => $_POST['login-pw']));



		$data = $statement->fetch();
		//$data = $statement->fetchAll();
		//print_r($data);

		//echo $data['role'];
		//die;
		//echo $statement->rowCount();
		$count = $statement->rowCount();
		if ($count > 0) {
			//login
			Session::init();
			Session::set('loggedIn', true);
			Session::set('role', $data['role']);
			//header('location:  ../dashboard');
			header('location:' . URL . '');
		}else {
			//show something
			header('location:' . URL . '');
			//echo "failed";
				
		}
		print_r($count);
	}
}